package com.sakura.oj.judge.codesandbox.impl;

import com.sakura.oj.judge.codesandbox.CodeSandbox;
import com.sakura.oj.judge.codesandbox.model.ExecuteCodeRequest;
import com.sakura.oj.judge.codesandbox.model.ExecuteCodeResponse;
import com.sakura.oj.judge.codesandbox.model.JudgeInfo;
import com.sakura.oj.model.enums.CodeSandBoxStatusEnums;
import com.sakura.oj.model.enums.JudgeInfoMessageEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例代码沙箱（仅为了跑通业务流程）
 */
@Slf4j
public class ExampleCodeSandbox implements CodeSandbox {
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        List<String> inputList = executeCodeRequest.getInputList();
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        executeCodeResponse.setOutputList(inputList);
        executeCodeResponse.setMessage("测试执行成功");
        executeCodeResponse.setStatus(CodeSandBoxStatusEnums.ACCEPTED.getValue());
        
        // 创建运行信息列表，每个输入用例对应一个运行信息
        List<JudgeInfo> runInfoList = new ArrayList<>();
        for (int i = 0; i < inputList.size(); i++) {
            JudgeInfo judgeInfo = new JudgeInfo();
            judgeInfo.setMessage(JudgeInfoMessageEnum.ACCEPTED.getText());
            judgeInfo.setMemory(100L);
            judgeInfo.setTime(100L);
            runInfoList.add(judgeInfo);
        }
        
        executeCodeResponse.setRunInfoList(runInfoList);
        return executeCodeResponse;
    }
}

